package com.admin;

import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 监控中心服务器启动入口
 *
 * @author yexi
 * @see EurekaClientAutoConfiguration
 * @see ConditionalOnNacosDiscoveryEnabled
 */
@EnableAdminServer
@SpringBootApplication
@EnableEurekaClient
@Slf4j
public class AdminServerCloudApplication {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext context = SpringApplication.run(AdminServerCloudApplication.class);
        Integer port = context.getBean(ServerProperties.class).getPort();
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        log.info("服务已启动，Admin UI访问地址：http://{}:{}", hostAddress, port == null ? 8080 : port);
    }
}
